/**
 * app.js
 */
define("app",["routes"],function(require){
	var routes = require("routes");
	var controllers = [];
	var urls = [];
	var routeMap = {};
	$.each(routes, function(url,controller){
		urls.push(url);
		controllers.push(controller);
	});
	seajs.use(controllers,function(){
		var $controllers = arguments;
		var app = angular.module('app',['ngRoute',"ui.bootstrap"]); 
		app.run(["$rootScope","$location",function($rootScope,$location){
			$rootScope.$on("$locationChangeStart",function(){
				console.log(JSON.stringify($location));
				//console.log(JSON.stringify());
				$rootScope.$$currentPath = $location.$$path;
				$rootScope.$$pathname = location.pathname;
				$(window).scrollTop(0);
				$rootScope.boxTypicalFullHeightStyle = {
					"min-height":$(window).height() - parseInt($('.page-content').css('padding-top')) - parseInt($('.page-content').css('padding-bottom'))
				};
				console.log(location.pathname);
			});
		}]);
		/**
		 * 拦截器
		 */
		app.factory("interceptor",[function(){
			return {
				response:function(response){
					/*
					if(typeof response.data ==  "object"){
						var err_code = response.data.err_code;
						if(err_code){
							if(err_code == 103){
								location.href = "#/login";
							}
						}
					}*/
					return response;
				}
			};
		}]);
		/**
		 * 配置
		 */
		app.config(
			["$routeProvider","$httpProvider",
				function($routeProvider,$httpProvider){
					$.each($controllers,function(index,$config){
						$routeProvider.when(urls[index],$config);
					});
					$httpProvider.interceptors.push("interceptor");
				}
		  ]);
		
		//开始运行
		app.run(function($rootScope,$location,$http){
			$rootScope.$login = {};
			$rootScope.$config = {
				headerNav:{
					showHeader:true,
					url:"/app/admin/header-nav.html?v="+$v,
					showNav:true
				}
			}
			$rootScope.headerNavInit = function(){
				console.log("sfd");
				setTimeout(function(){
					$startui.run();

				},1);
			};

			$rootScope.boxTypicalFullHeightStyle = {
				"min-height":$(window).height() - parseInt($('.page-content').css('padding-top')) - parseInt($('.page-content').css('padding-bottom'))
			};

			//$("#content_wrapper").show();
		});
		angular.bootstrap(angular.element(document.getElementById("wrapper")),["app"]);
	});
});